const TOKEN_KEY = 'token';
const PERMISSION = 'permission';
const SUBJECT = 'subject'
const isLogin = () => {
  return !!localStorage.getItem(TOKEN_KEY);
};

const getToken = () => {
  return localStorage.getItem(TOKEN_KEY);
};

const setTitle = (title:string) => {
  localStorage.setItem('document',title)
}

const setToken = (code: string) => {
  localStorage.setItem(TOKEN_KEY, code);
};

const setPermission = (permission: string) => {
  localStorage.setItem(PERMISSION, JSON.stringify(permission));
  
};
const subject = (subject: string) => {
  localStorage.setItem(SUBJECT,JSON.stringify(subject) );
};
const getPermission = (targetPermission: string) => {
  const permissions = JSON.parse(localStorage.getItem(PERMISSION) as any);
  return permissions.includes(targetPermission)
};

const clearToken = () => {
  localStorage.removeItem(TOKEN_KEY);
};

export { isLogin, getToken, setToken, clearToken, setPermission , getPermission,subject};
